home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / pxewin.zip / BROWSEFM.CPP < prev    next >
Text File  |  1992-02-19  |  13KB  |  526 lines

  1. // PXEWIN - (C) Copyright 1992 by Beam Engineering, INC.
  2.  
  3. // BROWSEFM.CPP //
  4.  
  5. // Contents ----------------------------------------------------------------
  6. //
  7. //    This module contains the members for the class BrowserFrame.
  8. //
  9. // End ---------------------------------------------------------------------
  10.  
  11. // External Reference Name for this Header ---------------------------------
  12.  
  13. #ifndef BROWSEFM_CPP
  14.     #define BROWSEFM_CPP
  15.  
  16. // End ---------------------------------------------------------------------
  17.  
  18. // Interface Dependencies --------------------------------------------------
  19.  
  20. #ifndef BROWSEFM_HPP
  21.     #include "browsefm.hpp"
  22. #endif // BROWSEFM_HPP //
  23.  
  24. #ifndef PXI_CPP
  25.     #include "pxi.cpp"
  26. #endif // PXI_CPP //
  27.  
  28. // End ---------------------------------------------------------------------
  29.  
  30. // member CursorWait of BrowserFrame //
  31.  
  32. inline void BrowserFrame::CursorWait(RTMessage)
  33. {
  34.     MyClass->hCursor = LoadCursor(NULL,IDC_WAIT);
  35.     SetCursor(MyClass->hCursor);
  36. }
  37.  
  38. // Description -------------------------------------------------------------
  39. //
  40. //    Sets cursor to wait type cursor.
  41. //
  42. // End ---------------------------------------------------------------------
  43.  
  44. // member CursorNormal of BrowserFrame //
  45.  
  46. inline void BrowserFrame::CursorNormal(RTMessage)
  47. {
  48.     MyClass->hCursor = LoadCursor(NULL,IDC_ARROW);
  49.     SetCursor(MyClass->hCursor);
  50. }
  51.  
  52. // member MenuItemDisable of BrowserFrame //
  53.  
  54. inline void BrowserFrame::MenuItemDisable(int item)
  55. {
  56.     HMENU hMenu;            /* Menu handle */
  57.  
  58.     // Get the menu handle
  59.  
  60.     hMenu = GetMenu(HWindow);
  61.  
  62.     // Disable menu item.
  63.  
  64.     EnableMenuItem(hMenu,item,MF_GRAYED);
  65. }
  66.  
  67. // Summary -----------------------------------------------------------------
  68. //
  69. //    Disables selected menu item.
  70. //
  71. // Parameter
  72. //
  73. //    item.  Is the menu item number to disable.
  74. //
  75. // End ---------------------------------------------------------------------
  76.  
  77. // member MenuItemEnable of BrowserFrame //
  78.  
  79. inline void BrowserFrame::MenuItemEnable(int item)
  80. {
  81.     HMENU hMenu;            /* Menu handle */
  82.  
  83.     // Get the menu handle
  84.  
  85.     hMenu = GetMenu(HWindow);
  86.  
  87.     // Enable menu item.
  88.  
  89.     EnableMenuItem(hMenu,item,MF_ENABLED);
  90. }
  91.  
  92. // Summary -----------------------------------------------------------------
  93. //
  94. //    Disables selected menu item.
  95. //
  96. // Parameter
  97. //
  98. //    item.  Is the menu item number to disable.
  99. //
  100. // End ---------------------------------------------------------------------
  101.  
  102. // member GetWindowClass of BrowserFrame //
  103.  
  104. inline void BrowserFrame::GetWindowClass(WNDCLASS& AWndClass)
  105. {
  106.     TWindow::GetWindowClass(AWndClass);
  107.     MyClass = &AWndClass;
  108. }
  109.  
  110. // Summary -----------------------------------------------------------------
  111. //
  112. //    Set up windows class object.
  113. //
  114. // End ---------------------------------------------------------------------
  115.  
  116. // constructor BrowserFrame //
  117.  
  118. inline BrowserFrame::BrowserFrame(LPSTR ATitle):
  119.         TMDIFrame(ATitle,"COMMANDS")
  120. {
  121.     // Create a windows class buffer
  122.  
  123.     MyClass = new WNDCLASS;
  124.  
  125.     // Open the PXEngine for windows in single client mode
  126.  
  127.     engine = new PXI("me",PXSINGLECLIENT);
  128.     if((error = engine->RetPXError()) != PXSUCCESS)
  129.     {
  130.  
  131.         MessageBox(HWindow,engine->RetPXErrorMsg(),
  132.         "Database Error",MB_OK);
  133.         CloseWindow();
  134.     }
  135. }
  136.  
  137. // Summary -----------------------------------------------------------------
  138. //
  139. //    Create a MDI Browser frame.
  140. //
  141. // Parameters
  142. //
  143. //    Pass of the frame title and commands menu to the MDI window.
  144. //
  145. // Description
  146. //
  147. //    Initialize engine in single client mode.  If you get an error, let
  148. //    the message box say what it is and close the window.
  149. //
  150. // End ---------------------------------------------------------------------
  151.  
  152. // member CreateChild of BrowserFrame //
  153.  
  154. inline PTWindowsObject BrowserFrame::CreateChild()
  155. {
  156.     NewChild = new Browser(this,GetChildCount()+1);
  157.  
  158.     // If the database exists, show it
  159.  
  160.     if(NewChild->GetDB() == EXISTS){
  161.  
  162.         // Enable save menus
  163.  
  164.         MenuItemEnable(CM_FILESAVE);
  165.         MenuItemEnable(CM_FILESAVEAS);
  166.         return GetApplication()->MakeWindow(NewChild);
  167.     }
  168.     // else kill the window and return NULL
  169.  
  170.     delete NewChild;
  171.     return NULL;
  172. }
  173.  
  174. // Summary -----------------------------------------------------------------
  175. //
  176. //    Creates a new Browser window.
  177. //
  178. // Return Value
  179. //
  180. //    Returns pointer to Browser window NewChild
  181. //
  182. // Functional Description
  183. //
  184. //      1.  Initialize a new child window Browser.
  185. //
  186. //    2.  If the new child exists, make the new window.
  187. //
  188. //    3.  Else kill the child and return NULL.
  189. //
  190. // End ---------------------------------------------------------------------
  191.  
  192. // destructor BrowserFrame //
  193.  
  194. inline BrowserFrame::~BrowserFrame()
  195. {
  196.     CloseChildren();
  197.     delete engine;
  198.     delete MyClass;
  199. }
  200.  
  201. // Summary -----------------------------------------------------------------
  202. //
  203. //    Call CloseChildren to close any open children.  Delete the engine
  204. //    and windows class objects.
  205. //
  206. // End ---------------------------------------------------------------------
  207.  
  208. // function CountChild //
  209.  
  210. void CountChild(Pvoid,Pvoid CountPtr)
  211. {
  212.     ++*(Pint)CountPtr;
  213. }
  214.  
  215. // Summary -----------------------------------------------------------------
  216. //
  217. //    This function keeps track of the number of child windows you have
  218. //    opened.
  219. //
  220. // Parameters
  221. //
  222. //    1.  First parameter is a pointer for the child.  It's not used.
  223. //
  224. //    2.  Second parameter is the counter.
  225. //
  226. // Return Value
  227. //
  228. //    None.
  229. //
  230. // Functional Description
  231. //
  232. //    For each window increment the counter.
  233. //
  234. // End ---------------------------------------------------------------------
  235.  
  236. // member build of BrowserFrame //
  237.  
  238. PTStreamable BrowserFrame::build()
  239. {
  240.     return new BrowserFrame(streamableInit);
  241. }
  242.  
  243. TStreamableClass RegBrowserFrame("BrowserFrame",BrowserFrame::build,
  244.     __DELTA(BrowserFrame));
  245.  
  246. // Description -------------------------------------------------------------
  247. //
  248. //    When the streamable constructor is called, TStreamable dispatches
  249. //    the build member to construct the object.  To do this, it must
  250. //    know where to find this member functions for the specific class.
  251. //    This is the reason for the stream registration.
  252. //
  253. // End ---------------------------------------------------------------------
  254.  
  255. // member read of BrowserFrame //
  256.  
  257. inline Pvoid BrowserFrame::read(Ripstream)
  258. {
  259.     return this;
  260. }
  261.  
  262. // member write of BrowserFrame //
  263.  
  264. inline void BrowserFrame::write(Ropstream)
  265. {
  266.  
  267. }
  268.  
  269. // member SetupWindow of BrowserFrame //
  270.  
  271. inline void BrowserFrame::SetupWindow()
  272. {
  273.     TMDIFrame::SetupWindow();
  274.     Show(SW_SHOWMAXIMIZED);
  275. }
  276.  
  277. // Summary -----------------------------------------------------------------
  278. //
  279. //    Call the MDI frame setup and set maximized show.
  280. //
  281. // End ---------------------------------------------------------------------
  282.  
  283. // member GetChildCount of BrowserFrame //
  284.  
  285. inline int BrowserFrame::GetChildCount()
  286. {
  287.     int Count = 0;
  288.     ForEach(CountChild,&Count);
  289.     return Count;
  290. }
  291.  
  292. // Summary -----------------------------------------------------------------
  293. //
  294. //    Lets the Frame window count the children.
  295. //
  296. // End ---------------------------------------------------------------------
  297.  
  298. // function SaveChildren //
  299.  
  300. void SaveChildren(Pvoid P,Pvoid os)
  301. {
  302.     PBrowser ptr;
  303.  
  304.     ptr = (PBrowser)P;
  305.     ptr->WriteChildren(*(opstream *)os);
  306. }
  307.  
  308. // Summary -----------------------------------------------------------------
  309. //
  310. //    Writes Child to the stream.
  311. //
  312. // Parameters
  313. //
  314. //    P.  Is the Child Object pointer.
  315. //
  316. //    os.  Is the Stream pointer.
  317. //
  318. // End ---------------------------------------------------------------------
  319.  
  320. // member WriteChildren of BrowserFrame //
  321.  
  322. void BrowserFrame::WriteChildren(Ropstream os)
  323. {
  324.     int num_children;            /* number of child windows */
  325.  
  326.     num_children = GetChildCount();
  327.  
  328.     os << num_children;
  329.     ForEach(SaveChildren,&os);
  330. }
  331.  
  332. // Summary -----------------------------------------------------------------
  333. //
  334. //    Get the child count and put it on the stream so the desktop reader
  335. //    will know how many children to take off the stream.
  336. //
  337. //    For each child, save it to the stream.
  338. //
  339. // Parameter
  340. //
  341. //    os.  Is the output stream.
  342.  
  343. // End ---------------------------------------------------------------------
  344.  
  345. // member ReadChildren of BrowserFrame //
  346.  
  347. void BrowserFrame::ReadChildren(Ripstream is)
  348. {
  349.     int num_children;            /* number of child windows */
  350.     int i;                    /* Child index */
  351.  
  352.     is >> num_children;
  353.  
  354.     // Create your children.
  355.  
  356.     for(i = 0;i < num_children;i++)
  357.     {
  358.         NewChild = new Browser(this,GetChildCount()+1);
  359.  
  360.         // If there are no errors in reading the child, make the
  361.         // window.
  362.  
  363.         if(!NewChild->ReadChildren(is))
  364.             GetApplication()->MakeWindow(NewChild);
  365.         else{
  366.             delete NewChild;
  367.             NewChild = NULL;
  368.         }
  369.     }
  370.  
  371.     // If you got children off the stream, enable the save menus.
  372.  
  373.     if(num_children > 0)
  374.     {
  375.         MenuItemEnable(CM_FILESAVE);
  376.         MenuItemEnable(CM_FILESAVEAS);
  377.     }
  378. }
  379.  
  380. // Summary -----------------------------------------------------------------
  381. //
  382. //    Read children off the stream.
  383. //
  384. //
  385. // Parameters
  386. //
  387. //    is.  Is the input stream.
  388. //
  389. // Functional Description
  390. //
  391. //      Get the number of children off the stream.
  392. //
  393. //      For each child, construct the child, call it's reader and make the
  394. //    window.
  395. //
  396. // End ---------------------------------------------------------------------
  397.  
  398. // member CreateBrowser of BrowserFrame //
  399.  
  400. inline void BrowserFrame::CreateBrowser(RTMessage)
  401. {
  402.     CreateChild();
  403. }
  404.  
  405. // Summary -----------------------------------------------------------------
  406. //
  407. //    Creates child window when command is dispatched.
  408. //
  409. // End ---------------------------------------------------------------------
  410.  
  411. // member CheckChildren of BrowserFrame //
  412.  
  413. inline void BrowserFrame::CheckChildren(RTMessage)
  414. {
  415.     int count;            /* Number of children */
  416.  
  417.     count = GetChildCount();
  418.     if(count == 1)
  419.     {
  420.         MenuItemDisable(CM_FILESAVE);
  421.         MenuItemDisable(CM_FILESAVEAS);
  422.     }
  423. }
  424.  
  425. // Summary -----------------------------------------------------------------
  426. //
  427. //    Responds to a message sent by a Browser to check your children
  428. //
  429. // Parameters
  430. //
  431. //    RTMessage.  This is the message sent.
  432. //
  433. // Functional Description --------------------------------------------------
  434. //
  435. //    Get the child count.  If there are no children then disable the save
  436. //    menus.
  437. //
  438. // End ---------------------------------------------------------------------
  439.  
  440. // member PXError of BrowserFrame //
  441.  
  442. inline void BrowserFrame::PXError(RTMessage)
  443. {
  444.     // If the new child still exists, get the engine error string
  445.     // and display it in the message box.
  446.  
  447.     if(NewChild)
  448.         MessageBox(HWindow,NewChild->my_display->RetPXErrorMsg(),
  449.             "DataBase Warning",MB_OK);
  450. }
  451.  
  452. // Summary -----------------------------------------------------------------
  453. //
  454. //    This will display Engine error messages in the MDI frame window.
  455. //
  456. // End ---------------------------------------------------------------------
  457.  
  458. // member OpenDeskTop of BrowserFrame //
  459.  
  460. inline void BrowserFrame::OpenDeskTop(RTMessage)
  461. {
  462.     char    sname[MAXPATH];            /* Desktop name */
  463.  
  464.     strcpy(sname,"*.dtf");
  465.     if(GetApplication()->ExecDialog(
  466.         new TFileDialog(this,SD_FILEOPEN,
  467.         sname)) == IDOK)
  468.     {
  469.         // Open the file for reading:
  470.  
  471.         ifpstream is(sname);
  472.  
  473.  
  474.         if(is.bad())
  475.             MessageBox(HWindow,"Unable to open file","File Error",
  476.                 MB_OK | MB_ICONEXCLAMATION);
  477.  
  478.         else
  479.             ReadChildren(is);
  480.         is.close();
  481.     }
  482. }
  483.  
  484. // Description -------------------------------------------------------------
  485. //
  486. //    Opens the desktop as it was last saved to the stream.  Create a file
  487. //    name mask and call the file dialog.  If file is found, create an
  488. //    input stream, check to see if it's OK and read the children off the
  489. //    stream.
  490. //
  491. // End ---------------------------------------------------------------------
  492.  
  493. // member SaveDeskTop of BrowserFrame //
  494.  
  495. inline void BrowserFrame::SaveDeskTop(RTMessage)
  496. {
  497.     char sname[MAXPATH];            /* Desktop name */
  498.  
  499.     strcpy(sname,"pxdesk.dtf");
  500.     if(GetApplication()->ExecDialog(
  501.         new TFileDialog(this,SD_FILESAVE,
  502.         sname)) == IDOK)
  503.     {
  504.         // Open the file:
  505.  
  506.         ofpstream os(sname);
  507.  
  508.         // Write the to the stream
  509.  
  510.         WriteChildren(os);
  511.  
  512.         // Close the stream:
  513.  
  514.         os.close();
  515.     }
  516. }
  517.  
  518. // Summary -----------------------------------------------------------------
  519. //
  520. //      Save the desktop to a file.  Construct a file mask.  Call the file
  521. //    dialog.  If the file is found, open the stream for output, write the
  522. //    children, and close the stream.
  523. //
  524. // End ---------------------------------------------------------------------
  525.  
  526. #endif // BROWSEFM_CPP //